package com.winit.core.websocket;

import com.winit.core.websocket.handler.MessageQueueHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import com.winit.core.websocket.handler.DefaultHandler;

/**
 * 注册websocket
 *
 * @author wangjian
 */

@Configuration
@EnableWebSocket
public class WsRouteConfig implements WebSocketConfigurer {

    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
//		注册websocket server实现类
//		使用Sockjs的注册方法 前端使用path时,要带上后缀,比如用ws协议,就要带上/api/websocket,其余类推。
        registry.addHandler(new DefaultHandler(), "/api")
                .setAllowedOrigins("*").withSockJS();

        registry.addHandler(new MessageQueueHandler(), "/mq")
                .setAllowedOrigins("*").withSockJS();
    }


}
